package com.dianxin.smartpark.service.device.impl;

import com.chinatelecom.response.common.CommonResponseBody;
import com.chinatelecom.response.utils.ResponseBodyWrapperUtil;
import com.dianxin.device.api.device.SmartParkDeviceSettingsRpcService;
import com.dianxin.device.api.device.dto.SmartDeviceSettingsDTO;
import com.dianxin.device.api.device.qo.SmartDeviceRpcQO;
import com.dianxin.smartpark.service.device.SmartParkDeviceSettingsService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangkai
 */
@Service
public class SmartParkDeviceSettingsServiceImpl implements SmartParkDeviceSettingsService {

    @Resource
    private SmartParkDeviceSettingsRpcService smartParkDeviceSettingsRpcService;
    @Override
    public CommonResponseBody<Boolean> saveDeviceSettings(SmartDeviceSettingsDTO vo) throws Exception {
        return smartParkDeviceSettingsRpcService.saveDeviceSettings(vo);
    }

    @Override
    public CommonResponseBody<Boolean> updateDeviceSettings(SmartDeviceSettingsDTO vo) throws Exception {
        return  smartParkDeviceSettingsRpcService.updateDeviceSettings(vo);
    }

    @Override
    public CommonResponseBody<Boolean> deleteDeviceSettings(SmartDeviceSettingsDTO vo) throws Exception {
        return  smartParkDeviceSettingsRpcService.deleteDeviceSettings(vo);
    }

    @Override
    public CommonResponseBody<SmartDeviceSettingsDTO> getDevicesSettings(SmartDeviceRpcQO qo) {
        CommonResponseBody<List<SmartDeviceSettingsDTO>> devicesSettings = smartParkDeviceSettingsRpcService.getDevicesSettings(qo);
        if (CollectionUtils.isEmpty(devicesSettings.getData())){
            return ResponseBodyWrapperUtil.success();
        }

        return  ResponseBodyWrapperUtil.successWrapper(devicesSettings.getData().get(0));
    }
}
